package org.example;

public class Test1 {
    //leetcode 盛最多水的容器 https://leetcode.cn/problems/container-with-most-water/description/?envType=study-plan-v2&envId=top-interview-150

    /**
     * 双指针
     * @param height
     * @return
     */
    public int maxArea(int[] height) {
        int n = height.length;
        int left = 0, right = n-1;
        int max = 0;
        while (left < right) {
            max = Math.max(max,Math.min(height[left],height[right])*(right-left));
            if (height[left] > height[right]) right--;
            else left++;
        }
        return max;
    }
}
